from selenium.webdriver.support.select import Select
from selenium import webdriver
import time
from selenium.webdriver.common.by import By


driver = webdriver.Chrome()
driver.maximize_window()
driver.get("file:///C:/TT/%E4%B9%A0%E7%9F%A5/15/python-study-15/%E7%AC%AC15%E5%A4%A9/selectDemo.html")
time.sleep(2)

# 定位到下拉框元素
select_ele = driver.find_element(By.CSS_SELECTOR, "select")
# 实例化一个下拉框对象
select_obj = Select(select_ele)

# # 索引选择
# for i in [2, 3, 1]:  # 山东、北京、深圳
#     select_obj.select_by_index(i)
#     time.sleep(2)

# # 通过value属性选择
# for value in ["chengdu", "shenzheng", "beijing"]:
#     select_obj.select_by_value(value)
#     time.sleep(2)

# # 通过文本值选择
# for text in ["成都", "深圳", "北京"]:
#     select_obj.select_by_visible_text(text)
#     time.sleep(2)

print(select_obj.options)

driver.quit()